import { FIVE_ELEMENT } from '../../constants/five-elements';
import { ConditionFactory } from '../../systems/condition-checker/factory';
import { CONDITION_TYPE } from '../../systems/condition-checker/type';
import { ItemFactory } from '../../systems/item/factory';
import { ITEM_RARITY, type CultivationSkillItemConfig } from './type';

export const CULTIVATION_SKILL_ITEM_ID = {
  /** 先天一气诀 */
  XIAN_TIAN_YI_QI_JUE: 'XIAN_TIAN_YI_QI_JUE',
  /** 万象观想法 */
  WAN_XIANG_GUAN_XIANG_FA: 'WAN_XIANG_GUAN_XIANG_FA',
  /** 九转筑基诀 */
  JIU_ZHUAN_ZHU_JI_JUE: 'JIU_ZHUAN_ZHU_JI_JUE',
  /** 归元养气篇 */
  GUI_YUAN_YANG_QI_PIAN: 'GUI_YUAN_YANG_QI_PIAN',
  /** 锻铁诀 */
  DUAN_TIE_JUE: 'DUAN_TIE_JUE',
  /** 长春功 */
  CHANG_CHUN_GONG: 'CHANG_CHUN_GONG',
  /** 引水诀 */
  YIN_SHUI_JUE: 'YIN_SHUI_JUE',
  /** 燃火功 */
  RAN_HUO_GONG: 'RAN_HUO_GONG',
  /** 聚土功 */
  JU_TU_GONG: 'JU_TU_GONG',
  /** 百战不殆 */
  BAI_ZHAN_BU_DAI: 'BAI_ZHAN_BU_DAI',
  /** 万古长春诀 */
  WAN_GU_CHANG_CHUN_JUE: 'WAN_GU_CHANG_CHUN_JUE',
} as const;

export type CultivationSkillItemId = keyof typeof CULTIVATION_SKILL_ITEM_ID;

export const CULTIVATION_SKILL_ITEM_DATA: CultivationSkillItemConfig[] = [
  ItemFactory.createCultivationSkillItemConfig({
    id: CULTIVATION_SKILL_ITEM_ID.XIAN_TIAN_YI_QI_JUE,
    name: '先天一气诀',
    rarity: ITEM_RARITY.COMMON,
    canSell: false,
  }),
  ItemFactory.createCultivationSkillItemConfig({
    id: CULTIVATION_SKILL_ITEM_ID.WAN_XIANG_GUAN_XIANG_FA,
    name: '万象观想法',
    rarity: ITEM_RARITY.COMMON,
  }),
  ItemFactory.createCultivationSkillItemConfig({
    id: CULTIVATION_SKILL_ITEM_ID.JIU_ZHUAN_ZHU_JI_JUE,
    name: '九转筑基诀',
    rarity: ITEM_RARITY.COMMON,
  }),
  ItemFactory.createCultivationSkillItemConfig({
    id: CULTIVATION_SKILL_ITEM_ID.GUI_YUAN_YANG_QI_PIAN,
    name: '归元养气篇',
    rarity: ITEM_RARITY.COMMON,
  }),
  ItemFactory.createCultivationSkillItemConfig({
    id: CULTIVATION_SKILL_ITEM_ID.DUAN_TIE_JUE,
    name: '锻铁诀',
    rarity: ITEM_RARITY.COMMON,
    studyConditions: [
      {
        type: CONDITION_TYPE.SPIRITUAL_ROOT,
        spiritualRoot: [FIVE_ELEMENT.METAL],
      },
    ],
  }),
  ItemFactory.createCultivationSkillItemConfig({
    id: CULTIVATION_SKILL_ITEM_ID.CHANG_CHUN_GONG,
    name: '长春功',
    rarity: ITEM_RARITY.COMMON,
    studyConditions: [
      {
        type: CONDITION_TYPE.SPIRITUAL_ROOT,
        spiritualRoot: [FIVE_ELEMENT.WOOD],
      },
    ],
  }),
  ItemFactory.createCultivationSkillItemConfig({
    id: CULTIVATION_SKILL_ITEM_ID.YIN_SHUI_JUE,
    name: '引水诀',
    rarity: ITEM_RARITY.COMMON,
    studyConditions: [
      {
        type: CONDITION_TYPE.SPIRITUAL_ROOT,
        spiritualRoot: [FIVE_ELEMENT.WATER],
      },
    ],
  }),
  ItemFactory.createCultivationSkillItemConfig({
    id: CULTIVATION_SKILL_ITEM_ID.RAN_HUO_GONG,
    name: '燃火功',
    rarity: ITEM_RARITY.COMMON,
    studyConditions: [
      {
        type: CONDITION_TYPE.SPIRITUAL_ROOT,
        spiritualRoot: [FIVE_ELEMENT.FIRE],
      },
    ],
  }),
  ItemFactory.createCultivationSkillItemConfig({
    id: CULTIVATION_SKILL_ITEM_ID.JU_TU_GONG,
    name: '聚土功',
    rarity: ITEM_RARITY.COMMON,
    studyConditions: [
      {
        type: CONDITION_TYPE.SPIRITUAL_ROOT,
        spiritualRoot: [FIVE_ELEMENT.EARTH],
      },
    ],
  }),
  ItemFactory.createCultivationSkillItemConfig({
    id: CULTIVATION_SKILL_ITEM_ID.BAI_ZHAN_BU_DAI,
    name: '百战不殆',
    author: {
      name: '少安',
      contact: '3296954289',
    },
    rarity: ITEM_RARITY.SUPREME,
    baseCultivationSpeed: 500,
    speedFn: (lv) => {
      const stage = Math.floor((lv - 1) / 5);
      return 100 * Math.pow(2, stage);
    },
    breakAt: (lv) => {
      return [ConditionFactory.createBattleLevelCondition(lv * 100)];
    },
  }),
  ItemFactory.createCultivationSkillItemConfig({
    id: CULTIVATION_SKILL_ITEM_ID.WAN_GU_CHANG_CHUN_JUE,
    name: '万古长春诀',
    rarity: ITEM_RARITY.SUPREME,
    baseCultivationSpeed: 500,
    studyConditions: [
      ConditionFactory.createSpiritualRootCondition([FIVE_ELEMENT.WOOD]),
      ConditionFactory.createCultivationSkillCondition(
        CULTIVATION_SKILL_ITEM_ID.CHANG_CHUN_GONG
      ),
    ],
    speedFn: (lv) => {
      const stage = Math.floor((lv - 1) / 5);
      return 100 * Math.pow(2, stage);
    },
    breakAt: (lv) => {
      return [ConditionFactory.createLifeCondition(lv * 100)];
    },
  }),
];
